package com.creative.accountsdk;

import android.os.Parcel;
import android.os.Parcelable;
import org.json.JSONObject;

/**
 * Created by creative on 15/7/6.
 */
public class Area  implements Parcelable,Cloneable {

    private long areaId;
    private Integer areaSort;     //排序
    private Integer areaIsDefault; //1  、 0
    private String areaCode;
    private String areaNameCN;
    private String areaNameEN;

    public Area() {

    }

    public Object clone() {
        Area o = null;
        try {
            o = (Area) super.clone();
        } catch (CloneNotSupportedException e) {
            e.printStackTrace();
        }
        return o;
    }

    public Area(long areaId, Integer areaSort, Integer areaIsDefault,
                String areaCode, String areaNameCN, String areaNameEN) {
        this.areaId = areaId;
        this.areaSort = areaSort;
        this.areaIsDefault = areaIsDefault;
        this.areaCode = areaCode;
        this.areaNameCN = areaNameCN;
        this.areaNameEN = areaNameEN;
    }

    @Override
    public int describeContents() {
        return 0;
    }

    public void writeToParcel(Parcel out, int flags) {
        out.writeLong(areaId);
        out.writeInt(areaSort);
        out.writeInt(areaIsDefault);

        out.writeString(areaCode);
        out.writeString(areaNameCN);
        out.writeString(areaNameEN);
    }

    public static final Parcelable.Creator<Area> CREATOR
            = new Parcelable.Creator<Area>() {
        public Area createFromParcel(Parcel in) {
            return new Area(in);
        }

        public Area[] newArray(int size) {
            return new Area[size];
        }
    };

    private Area(Parcel in) {
        areaId = in.readInt();
        areaSort = in.readInt();
        areaIsDefault = in.readInt();

        areaCode = in.readString();
        areaNameCN = in.readString();
        areaNameEN = in.readString();
    }

    public Area(Integer areaId, Integer areaSort, Integer areaIsDefault,
                String areaCode, String areaNameCN, String areaNameEN) {
        this.areaId = areaId;
        this.areaSort = areaSort;
        this.areaIsDefault = areaIsDefault;
        this.areaCode = areaCode;
        this.areaNameCN = areaNameCN;
        this.areaNameEN = areaNameEN;
    }

    public long getAreaId() {
        return areaId;
    }

    public void setAreaId(long areaId) {
        this.areaId = areaId;
    }

    public Integer getAreaSort() {
        return areaSort;
    }

    public void setAreaSort(Integer areaSort) {
        this.areaSort = areaSort;
    }

    public Integer getAreaIsDefault() {
        return areaIsDefault;
    }

    public void setAreaIsDefault(Integer areaIsDefault) {
        this.areaIsDefault = areaIsDefault;
    }

    public String getAreaCode() {
        return areaCode;
    }

    public void setAreaCode(String areaCode) {
        this.areaCode = areaCode;
    }

    public String getAreaNameCN() {
        return areaNameCN;
    }

    public void setAreaNameCN(String areaNameCN) {
        this.areaNameCN = areaNameCN;
    }

    public String getAreaNameEN() {
        return areaNameEN;
    }

    public void setAreaNameEN(String areaNameEN) {
        this.areaNameEN = areaNameEN;
    }

    public Area jsonToVO(JSONObject json) {
        setAreaId(json.optInt("areaId"));
        setAreaSort(json.optInt("areaSort"));
        setAreaIsDefault(json.optInt("areaIsDefault"));
        setAreaCode(json.optString("areaCode"));

        setAreaNameCN(json.optString("areaNameCN"));
        setAreaNameEN(json.optString("areaNameEN"));
        return this;
    }
}